import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 登录框的状态
    isOpenLogin: false,
    // Tost变量
    toast: {
      show: false,
      content: '',
      icon: '	icon-toast_chenggong'
    },
  },
  getters: {
  },
  mutations: {
    // 修改登录框的状态
    changeLoginShow(state, payload) {
      state.isOpenLogin = payload
    },
    // Tost开启
    toastShow(state, payload) {
      state.toast.show = true
      state.toast.content = payload.content
      switch (payload.icon) {
        // 警告
        case 'info':
          state.toast.icon = 'icon-toast-jinggao'
          break;
        // 成功
        case 'success':
          state.toast.icon = 'icon-toast_chenggong'
          break;
        // 失败
        case 'danger':
          state.toast.icon = 'icon-toast-shibai_huaban'
          break;
        // 加载中
        case 'loading':
          state.toast.icon = 'icon-loading'
          break;
        default:
          state.toast.icon = 'icon-toast-jinggao'
          break
      }
    },
    // Toast关闭
    toastDown(state) {
      state.toast.show = false
    }
  },
  actions: {
    // 2秒后关闭
    closeToast({ commit }, payload) {
      commit('toastShow', payload);
      setTimeout(() => {
        commit('toastDown')
      }, 2000)
    }
  },
  modules: {
  }
})
